package com.jbm.jbmsupplier.activity.searchconstrucation.view

import android.content.Intent
import android.support.design.widget.TextInputLayout
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.jbm.jbmsupplier.R
import com.jbm.jbmsupplier.activity.AllActivityApp
import com.jbm.jbmsupplier.activity.searchconstrucation.presenter.Serch_Presenter_Con
import com.jbm.jbmsupplier.activity.searchmanage.view.SearchManage
import com.jbm.jbmsupplier.utlis.ExitActivity
import kotlinx.android.synthetic.main.activity_sear_contruction.*
import kotlinx.android.synthetic.main.lz_titlehurdle.*

class SearContruction : AllActivityApp(), View.OnClickListener, SerchContruiconInter {
    override fun setContentView(): Int {
        return R.layout.activity_sear_contruction
    }

    override fun initIalizeView() {
        ExitActivity.getInstance().addActivity(this)
        serch_imagebutt.setOnClickListener(this)
        teleft.setOnClickListener(this)
        serch_image_tianjia.setOnClickListener(this)
        serchpresenter = Serch_Presenter_Con(this,this)
        tetitle.text = "搜索施工队"
        text_phot_serch.addTextChangedListener(textWar)
    }

    override fun finsh() {
        finish()
    }

    override fun getImageurl(): ImageView {
        return serch_image
    }

    override fun getImageButt(): ImageView {
       return serch_image_tianjia
    }

    override fun getTexviewshig(): TextView {
      return teshigogndui
    }

    override fun getTextViewPhot(): TextView {
        return tephoto
    }

    override fun getPhotErr(): TextInputLayout {
return edit_con_ser
    }

    override fun getAddSerchFriend() {//添加好友成功
        startActivity(Intent(this@SearContruction, SearchManage::class.java))
        finish()
    }

    override fun getSerchContMas() {//获得好友的信息
        serch_relative.visibility = View.VISIBLE
    }

    override fun getPhot(): String {//获取手机号
        return text_phot_serch.editableText.toString()
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.serch_imagebutt -> {
            serchpresenter!!.setSerchPhot()//调用查找施工队
            }
            R.id.teleft -> {
                this.finish()
            }
            R.id.serch_image_tianjia ->{
                serchpresenter!!.setAddFriendCon()//调用添加施工队
            }

        }
    }

    var serchpresenter: Serch_Presenter_Con? = null


var textWar =object :TextWatcher{
    override fun afterTextChanged(s: Editable?) {
     if (!s.toString().equals("")){
         edit_con_ser.isErrorEnabled=false
     }
        if (s!!.length==11){
         edit_con_ser.isErrorEnabled=false

     }
        if (s!!.length<11){
         serch_relative.visibility = View.GONE
     }
    }

    override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

    }

    override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

    }

}

}
